
選擇顏色按鈕,按下去對應Id後,進入剛剛寫的ColorActivity。
startActivityForResult(new Intent(this, ColorActivity.class), START_COLOR);
break;

Activity.RESULT_OK,就去switch,requestCode,選到後,把顏色接出來,key為"colorId",value沒有的話就是,Colors.LIGHTGREY.parseColor()這個顏色。

onClick事件,點入之後帶到PrefActivity。
PrefActivity裡面很特別繼承PreferenceActivity,主要是為了儲存我們想要的東西。xml,xml裡面有Preference、ListPreference,其中Preference在加入intent事件,intent至"com.example.linyanan.myapplication.ColorSetting.ColorActivity",這個Activity,自帶一個action叫做"android.intent.action.CHOOSE_COLOR",ListPreference則是加入自己寫的res/value/string檔案裡面的array,並沒有要他去哪個畫面。

PreferenceActivity是怎麼寫的。SharedPreferences sharedPreferences;
Preference preference;
SharedPreferences用來存東西。Preference則是為了要拿剛剛在xml中設計的兩個Preference。protected void onResume() {
super.onResume();
int color = sharedPreferences.getInt("DEFAULT_COLOR", -1);
if (color != -1) {
// 設定顏色說明
preference.setSummary(getString(R.string.default_color_summary) +
": " + EditActivity.getColors(color));
}}
onResume這個方法,是有關於生命週期,回來畫面時會調用,暫停時也會。color不是預設的,那麼就將字更改,並且加入所選顏色。